import os
src_path = r'E:\p3'
target_path = r'E:\p4'

def copy(src_path,target_path):
    # 获取文件夹里的内容
    filelist = os.listdir(src_path)
    # 变量列表
    print(filelist)
    for file in filelist:
        path = os.path.join(src_path,file)
        # 判断是文件还是文件夹
        if os.path.isdir(path):
            # 递归调用copy（）
            target_path = os.path.join(target_path,file)
            os.mkdir(target_path)
            copy(path,target_path)

        else:
            # 不是文件夹就直接复制
            with open(path,'rb') as rstream:
                content = rstream.read()
                path1 = os.path.join(target_path,file)
                with open(path1,'wb') as wstream:
                    wstream.write(content)
    else:
        print('复制完成')

copy(src_path,target_path)